package com.huaxia.controller.attend;

import com.huaxia.pojo.attend.BranchAttend;
import com.huaxia.pojo.attend.BranchLayerAttend;
import com.huaxia.pojo.attend.SaleDeptAttend;
import com.huaxia.pojo.attend.SaleDeptLayerAttend;
import com.huaxia.service.attend.AttendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import java.util.List;

/**
 * @author wangli 爱我华夏，爱我中华！
 * @date 2020/06/03 15:24
 */

@RestController
@RequestMapping("/attend")
public class AttendController {

    @Autowired
    private WebApplicationContext webApplicationContext;
    @Autowired
    private AttendService attendService;

    //获取中支TMS数据
    @GetMapping("/getBranchAttend")
    public List<BranchAttend> getBranchAttend(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchAttend> branchAttends = (List<BranchAttend>) servletContext.getAttribute("branchAttends");
        if(branchAttends==null){
            branchAttends = attendService.getBranchAttend();
            servletContext.setAttribute("branchAttends",branchAttends);
            return branchAttends;
        }
        return branchAttends;
    }
    //获取营服TMS数据
    @GetMapping("/getSaleDeptAttend")
    public List<SaleDeptAttend> getSaleDeptAttend(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptAttend> saleDeptAttends = (List<SaleDeptAttend>) servletContext.getAttribute("saleDeptAttends");
        if(saleDeptAttends==null){
            saleDeptAttends = attendService.getSaleDeptAttend();
            servletContext.setAttribute("saleDeptAttends",saleDeptAttends);
            return saleDeptAttends;
        }
        return saleDeptAttends;
    }
    //获取中支分层TMS数据
    @GetMapping("/getBranchLayerAttend")
    public List<BranchLayerAttend> getbranchLayerAttend(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchLayerAttend> branchLayerAttends = (List<BranchLayerAttend>) servletContext.getAttribute("branchLayerAttends");
        if(branchLayerAttends==null){
            branchLayerAttends = attendService.getBranchLayerAttend();
            servletContext.setAttribute("branchLayerAttends",branchLayerAttends);
            return branchLayerAttends;
        }
        return branchLayerAttends;
    }
    //获取营服分层TMS
    @GetMapping("/getSaleDeptLayerAttend")
    public List<SaleDeptLayerAttend> getSaleDeptLayerAttend(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptLayerAttend> saleDeptLayerAttends = (List<SaleDeptLayerAttend>) servletContext.getAttribute("saleDeptLayerAttends");
        if(saleDeptLayerAttends==null){
            saleDeptLayerAttends = attendService.getSaleDeptLayerAttend();
            servletContext.setAttribute("saleDeptLayerAttends",saleDeptLayerAttends);
            return saleDeptLayerAttends;
        }
        return saleDeptLayerAttends;
    }
}
